﻿using System.Collections;

namespace LocalisationResourceManager
{
    /// <summary>
    /// The class for the collection of invariant strings.
    /// </summary>
    public class InvariantStringDictonary : Hashtable
    {
        public InvariantStringDictonary(string invariantString, string path, string name, string translation, bool isNew)
        {
            var pg = new ResourcePath(invariantString, path, name, translation, isNew);
            this[path] = pg;
        }

        public ResourceRow this[string invariantString, string path, string name]
        {
            get
            {
                if (!base.ContainsKey(path))
                {
                    ResourceRow entry = null;

                    if (base.Count > 0)
                    {
                        foreach (DictionaryEntry de in this)
                        {
                            var pg = (ResourcePath)de.Value;

                            foreach (DictionaryEntry de2 in pg)
                            {
                                entry = (ResourceRow)de2.Value;
                                break;
                            }

                            break;
                        }
                    }

                    // reuse translation if existing.
                    this[path] = entry != null ? new ResourcePath(invariantString, path, name, entry.LocalizedValue, !Lrm.WriteUniqueResourceOnly) : new ResourcePath(invariantString, path, name, Lrm.ReplaceAltKey(invariantString), true);
                }

                return ((ResourcePath)base[path])[invariantString, path, name];
            }
        }
    }
}
